package com.newlink.building.userinfo.mvp.model

import com.newlink.building.common_base.base.BaseModel
import com.newlink.building.common_base.http.Base_RetrofitHelper
import com.newlink.building.common_base.model.bean.*
import com.newlink.building.userinfo.bean.CardInfo
import com.newlink.building.userinfo.bean.CardModifyInfo
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_AuthCardContract
import io.reactivex.Observable

/**
 * @author wangyang
 * @date 2022/9/20
 * @description 我的——关于页面的Model
 */
class Module_UserInfo_AuthCardModel : BaseModel(), Module_UserInfo_AuthCardContract.Model {

    override fun getAvailableArea(request: DeviceListRequest): Observable<HttpResult<DeviceListData>> {
        return Base_RetrofitHelper.service.getDeviceList(
            request.accessToken,
            request.page,
            request.limit,
            request.devName,
            request.devType
        )
    }

    override fun addCardInformation(
        token: String,
        uId: String,
        cardInfo: CardInfo
    ): Observable<HttpResult<StatusData>> {
        val body = AuthRequestBody(
            keyName = cardInfo.name,
            userId = cardInfo.userId,
            keyInfo = cardInfo.cardNum,
            keyType = AuthKeyTypeCard,
            macs = cardInfo.availableArea.toTypedArray()
        )
        return Base_RetrofitHelper.service.addAuthKey(token, body)
    }

    override fun modifyCardInformation(
        token: String,
        cardInfo: CardModifyInfo
    ): Observable<HttpResult<String>> {
        val body = AuthModifyBody(
            id = cardInfo.id,
            macs = cardInfo.availableArea.toTypedArray()
        )

        return Base_RetrofitHelper.service.modifyAuthKey(token, body)
    }

    override fun getFamilyMembers(token: String): Observable<HttpResult<FamilyListData>> {
        return Base_RetrofitHelper.service.getFamilyManagementList(token, 1, 20)
    }


}